﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;



using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class StuCauseEvalDetailLogic : CommonLogic<StuCauseEvalDetail, int>, IStuCauseEvalDetailLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        private IStuCauseEvalItemLogic _siLogic;
        public StuCauseEvalDetailLogic(ISchoolInfoLogic schoolLogic, IStuCauseEvalItemLogic siLogic)
        {
            _schoolLogic = schoolLogic;
            _siLogic = siLogic;
        }
        #region Implementation of ICommonLogic<StuCauseEvalDetail, int>

        /// <sammury>
        /// 创建对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(StuCauseEvalDetail entity)
        {
            return CreateObject(entity);
        }

        /// <sammury>
        /// 更新对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(StuCauseEvalDetail entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public StuCauseEvalDetail FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<StuCauseEvalDetail> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<StuCauseEvalDetail> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        #region Implementation of IStuCauseEvalDetailLogic

        /// <summary>
        /// 获取班级下所有学生在指定的日期内的所有学分评价之明细
        /// </summary>
        /// <param name="studentID">学生ID</param>
        /// <param name="causeID">学科ID</param>
        /// <param name="reportType">
        /// 报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<ScoreInputEntityWithCls> GetScoreInputEntityByStudent(int studentID, int causeID, int clsID, int reportType, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || term == null)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("CauseID", causeID);
            ht.Add("StudentID", studentID);
            ht.Add("ReportDate", new DateTime(year, month, 1));
            ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("ClsID", clsID);
            return FindCustomer<ScoreInputEntityWithCls>("StuCauseEvalDetail.GetScoreInputEntityByStudent", ht);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="stuCauseEvalDetail"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int InsertStuCauseEvalDetail(StuCauseEvalDetail stuCauseEvalDetail, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("StuCauseEvalDetail", stuCauseEvalDetail);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("StuCauseEvalDetail.InsertStuCauseEvalDetail", ht);
        }

        #endregion
    }
}